extends Resource
class_name FishingRewards

const REWARD_TYPES = {
	"fish_common": {
		"name": "普通鱼",
		"description": "一条普通的鱼",
		"value": 10,
		"icon": "res://assets/fishing/fish_common.png"
	},
	"fish_rare": {
		"name": "稀有鱼",
		"description": "一条稀有的鱼",
		"value": 50,
		"icon": "res://assets/fishing/fish_rare.png"
	},
	"fish_legendary": {
		"name": "传说鱼",
		"description": "一条传说中的鱼",
		"value": 200,
		"icon": "res://assets/fishing/fish_legendary.png"
	},
	"treasure": {
		"name": "宝箱",
		"description": "神秘的宝箱",
		"value": 100,
		"icon": "res://assets/fishing/treasure.png"
	}
}

static func give_fishing_reward(player, rarity: String = "random") -> Dictionary:
	var reward_type
	
	if rarity == "random":
		# 随机选择奖励类型
		var roll = randf()
		if roll < 0.6:  # 60% 普通鱼
			reward_type = "fish_common"
		elif roll < 0.9:  # 30% 稀有鱼
			reward_type = "fish_rare"
		elif roll < 0.98:  # 8% 传说鱼
			reward_type = "fish_legendary"
		else:  # 2% 宝箱
			reward_type = "treasure"
	else:
		reward_type = rarity
	print("获取奖励")
	EventBus.push_event("get_reward", [])	
	var reward = REWARD_TYPES[reward_type].duplicate()
	reward["type"] = reward_type
	
	## 添加到玩家库存
	#if player and player.has_method("add_item"):
		#player.add_item(reward_type, 1)
	
	
	# 显示获得奖励的通知
	#_show_reward_notification(reward)
	
	return reward

static func _show_reward_notification(reward: Dictionary):
	var notification_scene = preload("res://scenes/ui/reward_notification.tscn")
	if notification_scene:
		var notification = notification_scene.instantiate()
		notification.setup(reward)
		
		# 添加到当前场景
		var tree = Engine.get_main_loop()
		if tree and tree.has_method("get_root"):
			var root = tree.get_root()
			var current_scene = root.get_child(root.get_child_count() - 1)
			if current_scene:
				current_scene.add_child(notification)

static func get_reward_description(reward_type: String) -> String:
	if REWARD_TYPES.has(reward_type):
		return REWARD_TYPES[reward_type]["description"]
	return "未知奖励"
